﻿package mortal.game.view.mainUI.smallMap.view
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.smallMap.view.render.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class SmallMapCustomMapPointWin extends BaseWindow
    {
        private var _bg:ScaleBitmap;
        private var _txt1:GTextFiled;
        private var _txt2:GTextFiled;
        private var _btnSave:GButton;
        private var _btnCancel:GButton;
        private var _items:Array;

        public function SmallMapCustomMapPointWin(param1:ILayer = null)
        {
            super(param1);
            setSize(427, 269);
            this.title = Language.getString(20078);
            return;
        }// end function

        public function updateData(param1:Array) : void
        {
            var _loc_3:SmallMapCustomXYFixer = null;
            var _loc_2:int = 0;
            while (_loc_2 < 5)
            {
                
                _loc_3 = this._items[_loc_2] as SmallMapCustomXYFixer;
                _loc_3.data = param1[_loc_2];
                _loc_2++;
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_3:SmallMapCustomXYFixer = null;
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(10, 32, 413, 185, this, ImagesConst.PanelBg);
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.bold = true;
            _loc_1.color = 16777215;
            _loc_1.size = 14;
            pushUIToDisposeVec(UIFactory.bg(11, 35, 410, 22, this, ImagesConst.RegionTitleBg));
            this._txt1 = UIFactory.gTextField(Language.getString(20076), 42, 34, 200, 20, this, _loc_1);
            this._txt2 = UIFactory.gTextField(Language.getString(20077), 356, 34, 80, 20, this, _loc_1);
            this._btnSave = UIFactory.gButton(Language.getString(20083), 141, 230, 50, 25, this, "ButtonNew");
            this._btnCancel = UIFactory.gButton(Language.getString(20084), 228, 230, 50, 25, this, "ButtonNew");
            this._items = [];
            var _loc_2:int = 0;
            while (_loc_2 < 5)
            {
                
                _loc_3 = new SmallMapCustomXYFixer(_loc_2);
                _loc_3.x = 16;
                _loc_3.y = 60 + 32 * _loc_2;
                this.addChild(_loc_3);
                this._items.push(_loc_3);
                _loc_2++;
            }
            this._btnSave.configEventListener(MouseEvent.CLICK, this.saveHandler);
            this._btnCancel.configEventListener(MouseEvent.CLICK, this.cancelHandler);
            return;
        }// end function

        private function saveHandler(event:MouseEvent) : void
        {
            var _loc_4:SmallMapCustomXYFixer = null;
            var _loc_5:SCustomPoint = null;
            var _loc_6:String = null;
            var _loc_2:Boolean = false;
            var _loc_3:int = 0;
            while (_loc_3 < 5)
            {
                
                _loc_4 = this._items[_loc_3];
                if (_loc_4 == null)
                {
                }
                else
                {
                    _loc_5 = _loc_4.getChangeData();
                    if (_loc_5 == null)
                    {
                    }
                    else if (!MapNodeType.isWalk(GameMapUtil.getPointValueByMapId(_loc_5.mapId, _loc_5.point.x / Game.mapInfo.pieceWidth, _loc_5.point.y / Game.mapInfo.pieceHeight)))
                    {
                        MsgManager.showRollTipsMsg(Language.getStringByParam(20114, _loc_5.name, _loc_5.point.x, _loc_5.point.y));
                        _loc_2 = true;
                    }
                    else
                    {
                        _loc_6 = Language.getStringByParam(20080, (_loc_5.index + 1));
                        if (_loc_6 == _loc_5.name)
                        {
                            _loc_5.name = Language.getStringByParam(20115, (_loc_5.index + 1));
                        }
                        if (_loc_5.name == null || _loc_5.name.length > 8)
                        {
                            MsgManager.showRollTipsMsg(Language.getString(20116));
                            _loc_2 = true;
                        }
                        else
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.SmallMapSaveCustomPoint, _loc_5));
                        }
                    }
                }
                _loc_3++;
            }
            if (!_loc_2)
            {
                this.hide();
            }
            return;
        }// end function

        private function cancelHandler(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        override protected function setWindowCenter() : void
        {
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._bg = null;
            this._txt1.dispose(param1);
            this._txt1 = null;
            this._txt2.dispose(param1);
            this._txt2 = null;
            this._btnSave.dispose(param1);
            this._btnSave = null;
            this._btnCancel.dispose(param1);
            this._btnCancel = null;
            DisplayUtil.delNotUse(this._items, 0, param1);
            this._items = null;
            return;
        }// end function

    }
}
